package com.small.site.vo.req;

import com.small.site.pojo.SysUser;
import com.small.site.validation.ValidationType;
import com.small.site.vo.BaseForm;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.springframework.beans.BeanUtils;
import org.springframework.util.StringUtils;

import javax.validation.constraints.NotBlank;
import java.util.Date;


/**
 * @author xiaochi
 * @date 2021/12/15 21:04
 * @desc UserAddReqVo
 */
@Data
@EqualsAndHashCode(callSuper = true)
public class UserReqVo extends BaseForm<SysUser> {

    @NotBlank(message = "用户id不能为空",groups = ValidationType.update.class)
    private String id;

    @NotBlank(message = "账号不能为空")
    private String username;

    @NotBlank(message = "密码不能为空")
    private String password;

    private String phone;// 手机号

    private String email;// 邮箱

    private String nickName;// 昵称

    private String realName;// 真实姓名

    private Integer sex;// 性别

    private Long createWhere;// 创建来源(1.web 2.android 3.ios )

    private Integer status;// 账户状态(1.正常 2.锁定 )

    /**
     * 获取实例
     * @return 返回实体类
     */
    @Override
    public SysUser buildEntity() {
        SysUser sysUser = new SysUser();
        BeanUtils.copyProperties(this,sysUser);
        if (StringUtils.isEmpty(sysUser.getId())){
            sysUser.setCreateTime(new Date());
            sysUser.setUpdateTime(new Date());
        }else{
            sysUser.setUpdateTime(new Date());
        }
        return sysUser;
    }
}
